****APPENDIX FIGURE B1-B5****

cd "$main_dir/output/figures/appendix_b"

graph set window fontface "Palatino"

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_pooled_averages.dta"
merge 1:1 ccode using "$data_dir/raw/democ_autoc_switch_media.dta"
drop if _merge==2
drop _merge
merge 1:1 ccode using "$data_dir/raw/average_growth_rates_mpd.dta"
drop if _merge==2
drop _merge
merge 1:1 ccode using "$data_dir/raw/average_institutions.dta"
drop if _merge==2
drop _merge

merge 1:m ccode using "$data_dir/raw/mpd2023_clean.dta"
drop if _merge==2
drop _merge

sort ccode year

local varlist trust_govt_wo avg_10yr_exec avg_10yr_growth
foreach var of local varlist {
	cap drop r`var'
	reg `var' ln_gdppc if year==2008, r
	predict r`var', r
}

//--------------------------------------------------------
//Create Figure B1
//--------------------------------------------------------
scatter trust_govt_wo avg_10yr_growth if year==2008 & trust_govt_wo!=. & democracy==1, mlabel(ccode) msize(vsmall) mlabsize(vsmall) mlabcolor(black) legend(off) || lfit trust_govt_wo avg_10yr_growth if year==2008 & democracy==1, lcolor(maroon) graphregion(color(white)) bgcolor(white) ylabel(,labs(small) format(%9.2f)) xlabel(,labs(small)) xtitle("Average 10-Year Growth", margin(small) size(small)) ytitle("Trust in Government", margin(small) size(small)) title(Democracy) 
graph export "figure_b1.png", replace

//--------------------------------------------------------
//Create Figure B2
//--------------------------------------------------------
scatter trust_govt_wo avg_10yr_growth if year==2008 & trust_govt_wo!=. & autocracy==1, mlabel(ccode) msize(vsmall) mlabsize(vsmall) mlabcolor(black) legend(off) || lfit trust_govt_wo avg_10yr_growth if year==2008 & autocracy==1, lcolor(maroon) graphregion(color(white)) bgcolor(white) ylabel(,labs(small) format(%9.2f)) xlabel(-0.05(0.05)0.125,labs(small)) xtitle("Average 10-Year Growth", margin(small) size(small)) ytitle("Trust in Government", margin(small) size(small)) title(Autocracy) 
graph export "figure_b2.png", replace

//--------------------------------------------------------
//Create Figure B3
//--------------------------------------------------------
scatter trust_govt_wo avg_10yr_growth if year==2008 & trust_govt_wo!=. & switcher==1, mlabel(ccode) msize(vsmall) mlabsize(vsmall) mlabcolor(black) legend(off) || lfit trust_govt_wo avg_10yr_growth if year==2008 & switcher==1, lcolor(maroon) graphregion(color(white)) bgcolor(white) ylabel(,labs(small) format(%9.2f)) xlabel(-0.05(0.05)0.125,labs(small)) xtitle("Average 10-Year Growth", margin(small) size(small)) ytitle("Trust in Government", margin(small) size(small)) title(Switchers) 
graph export "figure_b3.png", replace

//--------------------------------------------------------
//Create Figure B4
//--------------------------------------------------------
gen sample = 1 if ccode!="VEN" & ccode!="YEM" & ccode!="CAF"
scatter rtrust_govt_wo ravg_10yr_growth if year==2008 & trust_govt_wo!=. & sample==1, mlabel(ccode) msize(vsmall) mlabsize(vsmall) mlabcolor(black) legend(off) || lfit rtrust_govt_wo ravg_10yr_growth if year==2008 & sample==1, lcolor(maroon) graphregion(color(white)) bgcolor(white) ylabel(,labs(small) format(%9.2f)) xlabel(,labs(small)) xtitle("Average 10-Year Growth (conditional)", margin(small) size(small)) ytitle("Trust in Government (conditional)", margin(small) size(small))
graph export "figure_b4.png", replace

//--------------------------------------------------------
//Create Figure B5
//--------------------------------------------------------
scatter rtrust_govt_wo ravg_10yr_exec if year==2008, mlabel(ccode) msize(vsmall) mlabsize(vsmall) mlabcolor(black) legend(off) || lfit rtrust_govt_wo ravg_10yr_exec if year==2008, lcolor(maroon) graphregion(color(white)) bgcolor(white) ylabel(,labs(small) format(%9.2f)) xlabel(,labs(small)) xtitle("Executive Constraints (conditional)", margin(small) size(small)) ytitle("Trust in Government (conditional)", margin(small) size(small)) 
graph export "figure_b5.png", replace
